"""
服务相关的 Pydantic 模式
"""
from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime
from decimal import Decimal


class ServiceBase(BaseModel):
    """服务基础模式"""
    name: str = Field(..., max_length=200, description="服务名称")
    description: Optional[str] = Field(None, description="服务描述")
    content: Optional[str] = Field(None, description="详细内容")
    icon_url: Optional[str] = Field(None, max_length=500, description="服务图标URL")
    category: Optional[str] = Field(None, max_length=100, description="服务分类")
    price: Optional[Decimal] = Field(None, description="价格")
    features: Optional[str] = Field(None, description="服务特点（JSON格式）")
    is_active: bool = Field(default=True, description="是否激活")
    is_featured: bool = Field(default=False, description="是否推荐")
    sort_order: int = Field(default=0, description="排序顺序")


class ServiceCreate(ServiceBase):
    """创建服务请求模式"""
    class Config:
        json_schema_extra = {
            "example": {
                "name": "环境影响评价",
                "description": "专业的环境影响评价服务",
                "content": "<p>我们提供全面的环境影响评价服务...</p>",
                "icon_url": "/images/service-eia.svg",
                "category": "评价服务",
                "price": 50000.00,
                "features": '["专业团队", "快速响应", "合规保证"]',
                "is_active": True,
                "is_featured": True,
                "sort_order": 1
            }
        }


class ServiceUpdate(BaseModel):
    """更新服务请求模式"""
    name: Optional[str] = Field(None, max_length=200, description="服务名称")
    description: Optional[str] = Field(None, description="服务描述")
    content: Optional[str] = Field(None, description="详细内容")
    icon_url: Optional[str] = Field(None, max_length=500, description="服务图标URL")
    category: Optional[str] = Field(None, max_length=100, description="服务分类")
    price: Optional[Decimal] = Field(None, description="价格")
    features: Optional[str] = Field(None, description="服务特点（JSON格式）")
    is_active: Optional[bool] = Field(None, description="是否激活")
    is_featured: Optional[bool] = Field(None, description="是否推荐")
    sort_order: Optional[int] = Field(None, description="排序顺序")


class ServiceResponse(ServiceBase):
    """服务响应模式"""
    id: int
    created_at: datetime
    updated_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class ServiceListResponse(BaseModel):
    """服务列表响应模式"""
    items: List[ServiceResponse]
    total: int
    page: int
    size: int
    pages: int


class ServiceCategoryResponse(BaseModel):
    """服务分类响应模式"""
    category: str
    count: int